package org.wattdepot.gdata.kukuicup.updater;

import static org.junit.Assert.assertEquals;
import org.junit.Test;

/**
 * Tests to ensure the RollingData abstraction works correctly.
 * @author Philip Johnson
 */
public class TestRollingData {

  /**
   * Tests simple use of the data abstraction.
   */
  @Test
  public void testRollingData() {
    RollingData rollingData = new RollingData(3);
    rollingData.initialize("foo", "bar");
    for (RollingData.Entry entry : rollingData) {
      assertEquals("Checking simple data", entry.data, "bar");
      assertEquals("Checking simple timestamp", entry.lastUpdate, "foo");
    }
  }
  
  /**
   * Test that the queue removes entries correctly.
   */
  @Test 
  public void testRollingDataSize() {
    RollingData rollingData = new RollingData(3);
    for (int i = 0; i < 10; i++) {
      rollingData.add(String.valueOf(i), String.valueOf(i));
    }
    
    assertEquals("Checking most recent data", "9", rollingData.getLastTimeStamp());
    
    int j = 9;
    for (RollingData.Entry entry : rollingData) {
      assertEquals("Checking rolled data", String.valueOf(j), entry.data);
      j--;
    }
  }
}
